﻿using facebook.businuss.netcore.sdk.Enum;
using facebook.businuss.netcore.sdk.Model;
using facebook.businuss.netcore.sdk.Model.Response;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace facebook.businuss.netcore.sdk.Sdk
{
    public class APIRequestGetInsights : APIRequest
    {

        public APIRequestGetInsights(APIContext context, String nodeId, String endpoint, String method, List<String> paramNames)
            : base(context, nodeId, endpoint, method, paramNames)
        {

        }

        public APIRequestGetInsights(String nodeId, APIContext context)
            : this(context, nodeId, "/insights", "GET", PARAMS.ToList())
        {

        }

        public List<AdsInsights> getLastResponse()
        {
            return null;
        }
        public static readonly string[] PARAMS =
            {
              "action_attribution_windows",
              "action_breakdowns",
              "action_report_time",
              "breakdowns",
              "date_preset",
              "default_summary",
              "export_columns",
              "export_format",
              "export_name",
              "fields",
              "filtering",
              "level",
              "product_id_limit",
              "sort",
              "summary",
              "summary_action_breakdowns",
              "time_increment",
              "time_range",
              "time_ranges",
              "use_account_attribution_setting",
              "use_unified_attribution_setting",
    };

        public static readonly string[] FIELDS = { };

        public APIRequestGetInsights setFiltering(List<object> filtering)
        {
            setParam("filtering", filtering);
            return this;
        }
        public APIRequestGetInsights setFiltering(String filtering)
        {
            setParam("filtering", filtering);
            return this;
        }
        public APIRequestGetInsights setLevel(EnumLevel level)
        {
            setParam("level", level.ToString());
            return this;
        }
        public APIRequestGetInsights setLevel(String level)
        {
            setParam("level", level);
            return this;
        }

        public APIRequestGetInsights setTimeRange(Object timeRange)
        {
            setParam("time_range", timeRange);
            return this;
        }
        public APIRequestGetInsights setTimeRange(String timeRange)
        {
            setParam("time_range", timeRange);
            return this;
        }

        //public APIRequestGetInsights setBreakdowns(List<EnumBreakdowns> breakdowns)
        //{
        //    setParam("breakdowns", breakdowns);
        //    return this;
        //}
        public APIRequestGetInsights setBreakdowns(String breakdowns)
        {
            setParam("breakdowns", breakdowns);
            return this;
        }

        public APIRequestGetInsights setBreakdowns(List<string> breakdowns)
        {
            this.setParam("breakdowns", breakdowns.ToArray());
            return this;
        }

        public APIRequestGetInsights setDatePreset(EnumDatePreset datePreset)
        {
            this.setParam("date_preset", datePreset.ToString());
            return this;
        }


        public APIRequestGetInsights requestFields(List<String> fields)
        {
            return this.requestFields(fields, true);
        }

        public APIRequestGetInsights requestFields(List<String> fields, bool value)
        {
            fields.ForEach(f =>
            {
                requestField(f, value);
            });
            return this;
        }

        public APIRequestGetInsights requestField(String field)
        {
            this.requestField(field, true);
            return this;
        }

        public APIRequestGetInsights requestField(String field, bool value)
        {
            base.requestFieldInternal(field, value);
            return this;
        }


        public List<AdsInsights> execute(Dictionary<String, Object> extraParams)
        {
            ResponseWrapper rw = base.execute(extraParams);

            var temData= rw==null?null:JsonConvert.DeserializeObject<BaseResponse<List<AdsInsights>>>(rw.Body);
            return temData == null ? null : temData.Data;
        }
        public List<AdsInsights> execute()
        {
            return execute(new Dictionary<string, object>());
        }

    }
}

